//
//  MineViewController.m
//  Wedding fantastic
//
//  Created by ZLM on 15/6/30.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "MineViewController.h"

@interface MineViewController ()

@end

@implementation MineViewController
-(void)dealloc{
    [_myTableView release];
    [_string release];
    [_text release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    // 字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor brownColor],NSForegroundColorAttributeName,nil]];
    
//    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonAction:)];
   //清除缓存按钮
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"清除缓存" style:UIBarButtonItemStylePlain target:self action:@selector(clearCacheAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor brownColor];
    
    //清除缓存按钮
//    UIButton *clearCache = [UIButton buttonWithType:UIButtonTypeCustom];
//    clearCache.frame = CGRectMake(50, 250, 80, 20);
//    [clearCache setTitle:@"清除缓存" forState:UIControlStateNormal];
//    [clearCache setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [self.view addSubview:clearCache];
//    [clearCache addTarget:self action:@selector(clearCacheAction) forControlEvents:UIControlEventTouchUpInside];
    
    //图片
    UIImageView *aimageVC = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 200*kHeight/667)];
    aimageVC.image = [UIImage imageNamed:@"~ADS2L(QKVDW5)P6$][~QXQ"];
    [self.view addSubview:aimageVC];
    [aimageVC release];
    
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, aimageVC.frame.origin.y+aimageVC.frame.size.height, kWidth, (667-aimageVC.frame.size.height-49-64)*kHeight/667) style:UITableViewStylePlain];
    
    self.myTableView.tableHeaderView.hidden = true;
    //取消cell的线
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.myTableView.tableHeaderView isHidden];
    //取消TableView的上下滚动效果
    self.myTableView.scrollEnabled = NO;
    
    self.myTableView.backgroundColor = [UIColor whiteColor];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.tableFooterView = [[UIView alloc]init];
    [self.view addSubview:self.myTableView];
    [_myTableView release];
    
    UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.backBarButtonItem = bar;
    
//    [self playVideo];
}
//清除缓存方法
-(void)clearCacheAction:(UIButton *)button
{
    
    NSLog(@"清除缓存");
    //计算图片缓存大小
    NSLog(@"计算缓存图片大小");
    //我们学过的单例   NSUserDefaults    UIApplication   NSFileManager
    NSUInteger size = [[SDImageCache sharedImageCache] getSize];

    
    CGFloat mb = size / 1024.0 / 1024.0;
    NSString *string = [NSString stringWithFormat:@"%.2fMB", mb];
    NSLog(@"图片缓存为 = %@", string);
    NSString *message = [NSString stringWithFormat:@"当前缓存为 = %@ ,正在清除缓存...", string];
    UIAlertView *alterView = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    
    [alterView show];
    //清空图片缓存
    NSLog(@"清除缓存");
    [[SDImageCache sharedImageCache] clearDisk];
    

    
    

    [alterView release];
    NSUInteger size2 = [[SDImageCache sharedImageCache] getSize];
    CGFloat mb2 = size2 / 1024.0 / 1024.0;
    self.string = [NSString stringWithFormat:@"%.2fMB", mb2];
    [self.myTableView reloadData];
}
-(void)viewWillDisappear:(BOOL)animated{
    [self.myTableView reloadData];

}
////视频相关
//- (void)playVideo{
//    NSURL *url = [NSURL URLWithString:@"http://krtv.qiniudn.com/150522nextapp"];
//    [self addVideoPlayerWithURL:url];
//}
//
//- (void)addVideoPlayerWithURL:(NSURL *)url{
//    if (!self.videoController) {
//        CGFloat width = [UIScreen mainScreen].bounds.size.width;
//        self.videoController = [[KrVideoPlayerController alloc] initWithFrame:CGRectMake(0, 64, width, width*(9.0/16.0))];
//        __weak typeof(self)weakSelf = self;
//        [self.videoController setDimissCompleteBlock:^{
//            weakSelf.videoController = nil;
//        }];
//        [self.videoController setWillBackOrientationPortrait:^{
//            [weakSelf toolbarHidden:NO];
//        }];
//        [self.videoController setWillChangeToFullscreenMode:^{
//            [weakSelf toolbarHidden:YES];
//        }];
//        [self.view addSubview:self.videoController.view];
//    }
//    self.videoController.contentURL = url;
//    
//}
////隐藏navigation tabbar 电池栏
//- (void)toolbarHidden:(BOOL)Bool{
//    self.navigationController.navigationBar.hidden = Bool;
//    self.tabBarController.tabBar.hidden = Bool;
//    [[UIApplication sharedApplication] setStatusBarHidden:Bool withAnimation:UIStatusBarAnimationFade];
//}
//-(void)rightButtonAction:(UIButton *)button{
//    LoginViewController *loginVC = [[LoginViewController alloc]init];
//    [self setModalPresentationStyle:UIModalPresentationFullScreen];
//    [self presentViewController:loginVC animated:YES completion:^{
//        NSLog(@"模态登陆页面");
//    
//}];
//}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return 1;

}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *myCell = @"reusedCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myCell];
    
    if (cell==nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myCell];
    }
    if(indexPath.row == 0){
        cell.textLabel.text = @"收藏的套餐、案例";
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"真心推荐";
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"关注的商家";
    }
    if (indexPath.row == 3) {
        
        //图片缓存
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        CGFloat mb = size / 1024.0 / 1024.0;
        self.string = [NSString stringWithFormat:@"%.2fMB", mb];
        
//        cell.textLabel.backgroundColor = [UIColor whiteColor];
        cell.textLabel.lineBreakMode = NSLineBreakByCharWrapping;
        
        cell.textLabel.text = [NSString stringWithFormat:@"当前缓存为： %@",self.string];
        cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13];
        cell.textLabel.textColor = [UIColor brownColor];
        
    }
            return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        taoCanAnLiVC *taoCanVC = [[taoCanAnLiVC alloc]init];
        [self.navigationController pushViewController:taoCanVC animated:YES];
    }
    if (indexPath.row == 1) {
//        shouCangShangPinVC *shouCangShangVC = [[shouCangShangPinVC alloc]init];
//        [self.navigationController pushViewController:shouCangShangVC animated:YES];
        RecommendViewController *recVC = [[RecommendViewController alloc]init];
        [self.navigationController pushViewController:recVC animated:YES];
    
    }
    if (indexPath.row == 2) {
        guanZhuShangJiaVC *guanZhuShangVC = [[guanZhuShangJiaVC alloc]init];
        [self.navigationController pushViewController:guanZhuShangVC animated:YES];
    }
    if (indexPath.row == 3) {
        NSString *message = [NSString stringWithFormat:@"当前缓存为 = %@", self.string];
        UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [view show];
        
        //清空图片缓存
        NSLog(@"清除缓存");
        [[SDImageCache sharedImageCache] clearDisk];
        
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        CGFloat mb = size / 1024.0 / 1024.0;
        self.string = [NSString stringWithFormat:@"%.2fMB", mb];
        [self.myTableView reloadData];
    }

    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80*kHeight/667;
}
//-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//    UIImageView *aimageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 375, 300)];
//    aimageView.backgroundColor = [UIColor whiteColor];
//    aimageView.image = [UIImage imageNamed:@"placeHoderImage"];
////    UIButton *abutton = [UIButton buttonWithType:UIButtonTypeCustom];
////    abutton.center = aimageView.center;
//    
//    return aimageView;
//    
//}
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    return 280;
//}

//-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//    if (section == 0) {
//        return @"收藏的套餐、案例";
//    }
//    if(section == 1){
//    
//        return @"收藏的商品";
//    }
//    if(section == 2){
//    
//        return @"关注的商家";
//    }
//    return @"";
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
